import React, { Component } from "react";
import {
  BrowserRouter as Router,
  Switch,
  Route,
  Redirect,
} from "react-router-dom";
import { connect } from "react-redux";
import BoilerHdpi from "./pages/BoilerHdpi";


//二级目录的名称
let secondDirName = '/boiler'

class App extends Component {
  componentDidMount() {}

  //做重定向
  redirectUrl() {

   let pathname = window.location.pathname;

   switch (pathname) {

    case '/': case `${secondDirName}/hdpi`:  
      return <Redirect to="/hdpi" />;

    default:
      return <Redirect to="/hdpi" />;

   };

  }

  render() {
    return (
      <Router basename={secondDirName}>

        <Route path="/" component={BoilerHdpi} />
        { this.redirectUrl() }
        
      </Router>
    );
  }
}

/*
App.propTypes = {
  dispatch: PropTypes.func.isRequired,
  quote: PropTypes.string,
  isAuthenticated: PropTypes.bool.isRequired,
  errorMessage: PropTypes.string
};
*/

//These props come from the application's
//state when it is started
function mapStateToProps(state) {
  const { quotes, auth } = state;
  const { quote, authenticated } = quotes;
  const { isAuthenticated, errorMessage } = auth;

  return {
    quote,
    isSecretQuote: authenticated,
    isAuthenticated,
    errorMessage,
  };
}

export default connect(mapStateToProps)(App);
